/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mouseident;

import java.math.BigInteger;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Enumeration;

/**
 *
 * @author matze
 */
public class Result {

    String identHash;
    int age;
    int sex;
    ArrayList<Node> parcour = new ArrayList<Node>();
    ArrayDeque<Event> history = new ArrayDeque<Event>();
    float totalDirectDistance = 0;
    

    public Result() {
        identHash = this.generateHashIdent();
    }

    public void setAge(int NewAge) {
        age = NewAge;
    }

    public void setSex(int NewSex) {
        sex = NewSex;
    }

    public void setParcour(ArrayList<Node> NewParcour) {
        parcour = NewParcour;
        totalDirectDistance = 0;
        for (int i=1; i<parcour.size();i++) {
            float dx = parcour.get(i-1).getX() - parcour.get(i).getX();
            float dy =parcour.get(i-1).getY() - parcour.get(i).getY();
            totalDirectDistance += Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
        }
    }

    public void setHistory(ArrayDeque<Event> NewHistory) {
        history = NewHistory;
    }





    private String generateHashIdent() {
        String result = "";
        try {
            String hashString = "";
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            while (nis.hasMoreElements()) {
                NetworkInterface ni = nis.nextElement();

                byte[] mac = ni.getHardwareAddress();
                if (mac != null) {
                    for (byte b : mac) {
                        hashString += "" + Math.abs(Integer.valueOf(b));
                    }
                }
            }
            hashString += System.getProperty("user.name");
            hashString += Calendar.getInstance().getTimeInMillis();
            hashString += Math.random() * 100000;

                byte[] bytesOfMessage = hashString.getBytes("UTF-8");
                MessageDigest md = MessageDigest.getInstance("MD5");
                byte[] digest = md.digest(bytesOfMessage);
                BigInteger bi = new BigInteger(digest).abs();
                result = bi.toString(16);
        } catch (Exception ex) {
            for (int i=0; i<3;i++) {
                result += Math.round (Math.random() * 100000);
            }
        }
        return result;
    }



}
